****APPENDIX FIGURE E3-E4****

cd "$main_dir/output/figures/appendix_e"

graph set window fontface "Palatino"

global basic 	marital edu
global econ	    employment_status occupation income imputed_income
global design 	survey_year age language
global polit    ideology party_member

//--------------------------------------------------------
//Define relevant program
//--------------------------------------------------------

capture program drop standardize
program define standardize
	
	args depvar
	
	cap drop z*
	local varlist `depvar' wgrowth_rate_1
	foreach var of local varlist {
		egen z`var' = std(`var') if e(sample)==1
}														

end

//--------------------------------------------------------
//Read in relevant data
//--------------------------------------------------------

clear
use "$data_dir/clean/shp_final_panel.dta"

gen dummy = 1 if trust_fed_govt_med!=.
bys idpers: egen total_obs = total(dummy)

xtset idpers survey_year

cap drop sample
gen sample = 1 if live_switz==1 & total_obs>4 & total_obs!=. & age>=15 & age!=.

egen canton_survey_year = group(canton survey_year)

//--------------------------------------------------------
//Create Figure E3
//--------------------------------------------------------

matrix coef1 = J(16, 3, .)
	matrix coln coef1 = coefficients lcl ucl
	matrix rown coef1 = "1999" "2000" "2001" "2002" "2003" "2004" ///
						"2005" "2006" "2007" "2008" "2009" "2011" ///
						"2014" "2017" "2020" "2023"

local i = 1
foreach x in ///
	1999 2000 2001 2002 2003 2004 ///
	2005 2006 2007 2008 2009 2011 ///
	2014 2017 2020 2023 ///
	{
		qui reghdfe trust_fed_govt_med wgrowth_rate_1 if survey_year!=`x' & sample==1, absorb(canton $basic $design $econ $polit idpers) cluster(idhous yob)
		qui standardize trust_fed_govt_med
		qui reghdfe ztrust_fed_govt_med zwgrowth_rate_1 if e(sample)==1, absorb(canton $basic $design $econ $polit idpers) cluster(idhous yob) level(95)
		
		mat os = r(table)
		mat coef1[`i',1] = os[1,1]
		mat coef1[`i',2] = os[5,1]
		mat coef1[`i',3] = os[6,1]
		
		di "Regression for `x' dropped complete"
		local ++i
	}

qui reghdfe trust_fed_govt_med wgrowth_rate_1 if sample==1, absorb(canton $basic $design $econ $polit idpers) cluster(idhous yob) level(95)
standardize trust_fed_govt_med
qui reghdfe ztrust_fed_govt_med zwgrowth_rate_1 if e(sample)==1, absorb(canton $basic $design $econ $polit idpers) cluster(idhous yob) level(95)
scalar beta = _b[zwgrowth_rate_1]
coefplot (matrix(coef1[,1]), ci((coef1[,2] coef1[,3]))), ///
	graphregion(color(white)) bgcolor(white) xline(0, lcolor(maroon)) xlabel(-0.02(0.02)0.08,labs(vsmall)) ylabel(,labs(vsmall)) xline(`=beta', lpattern(dash) lcolor(maroon)) ///
	ytitle("Survey Year Dropped",size(small) margin(small)) xtitle("Effect Size", size(small))
	graph export "figure_e3.png", replace


//--------------------------------------------------------
//Create Figure E4
//--------------------------------------------------------

matrix coef1 = J(26, 3, .)
	matrix coln coef1 = coefficients lcl ucl
	matrix rown coef1 = "AG" "AI" "AR" "BE" "BL" "BS" "FR" ///
						"GE" "GL" "GR" "JU" "LU" "NE" "NW" ///
						"OW" "SG" "SH" "SO" "SZ" "TG" "TI" ///
						"UR" "VD" "VS" "ZG" "ZH"
	
local i = 1
foreach x in ///
	AG AI AR BE BL BS FR ///
	GE GL GR JU LU NE NW ///
	OW SG SH SO SZ TG TI ///
	UR VD VS ZG ZH ///
	{
		qui reghdfe trust_fed_govt_med wgrowth_rate_1 if canton_code!="`x'" & sample==1, absorb(canton $basic $design $econ $polit idpers) cluster(idhous yob)
		qui standardize trust_fed_govt_med
		qui reghdfe ztrust_fed_govt_med zwgrowth_rate_1 if e(sample)==1, absorb(canton $basic $design $econ $polit idpers) cluster(idhous yob) level(95)
		
		mat os = r(table)
		mat coef1[`i',1] = os[1,1]
		mat coef1[`i',2] = os[5,1]
		mat coef1[`i',3] = os[6,1]
		
		di "Regression for `x' dropped complete"
		local ++i
	}

qui reghdfe trust_fed_govt_med wgrowth_rate_1 if sample==1, absorb(canton $basic $design $econ $polit idpers) cluster(idhous yob) level(95)
standardize trust_fed_govt_med
qui reghdfe ztrust_fed_govt_med zwgrowth_rate_1 if e(sample)==1, absorb(canton $basic $design $econ $polit idpers) cluster(idhous yob) level(95)
scalar beta = _b[zwgrowth_rate_1]
coefplot (matrix(coef1[,1]), ci((coef1[,2] coef1[,3]))), ///
	graphregion(color(white)) bgcolor(white) xline(0, lcolor(maroon)) xlabel(-0.02(0.02)0.08,labs(vsmall)) ylabel(,labs(vsmall)) xline(`=beta', lpattern(dash) lcolor(maroon)) ///
	ytitle("Canton Dropped",size(small) margin(small)) xtitle("Effect Size", size(small))
	graph export "figure_e4.png", replace



